<?php

use app\staff\Hash;

/**
 * 加密
 * @param string $value
 * @param int $cost
 * @param float $timeTarget
 * @return false|string
 */
function hashEncryption(string $value, int $cost = 8, float $timeTarget = 0.05)
{
    do {
        $cost++;
        $start = microtime(true);
        $password = Hash::makePasswordHash($value, $cost);
        $end = microtime(true);
    } while (($end - $start) < $timeTarget);

    return $password;
}

/**
 * 验证
 * @param string $value
 * @param string $hashValue
 * @return bool
 */
function hashValidate(string $value, string $hashValue): bool
{
    return Hash::validatePasswordHash($value, $hashValue);
}